package com.waimai.common;

import com.waimai.domain.Category;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLIntegrityConstraintViolationException;

//全局异常捕获类
@ControllerAdvice(annotations = {RestController.class,Controller.class, Service.class})
@ResponseBody
@Slf4j
public class GolbalExceptionHandler {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R<String> exceptionHandler(SQLIntegrityConstraintViolationException ex){
        log.info(ex.getMessage());
        return R.error("添加失败");
    }
    @ExceptionHandler(CustomException.class)
    public R<String> exceptionHandler1(SQLIntegrityConstraintViolationException ex) {
        log.info(ex.getMessage());
        return R.error(ex.getMessage());
    }


}
